INFORMAZIONI¶

  • Autori: Leonardo Babbucci, Gabriele Dominelli,
  • Gruppo V
  • Data Science 2022

In questo notebook è stato preso un dataset sui laptop e le loro specifiche tecniche da kaddle. Questo dataset possiede 1303 righe ed ognuna di esse è un laptop differente. Ogni colonna invece è una specifica del laptop. Con questo dataset si possono fare varie comparazioni ed analisi interessanti, alcune delle quali esposte di seguito. Tra le analisi più interessanti vi sono: analisi sui sistemi operativi più usati, quantità di laptops per categoria, analisi sulla distribuzione dei prezzi dei laptops per modello di CPU e GPU e distribuzione prezzi per sistema operativo montato.

Progetto pratico dataset laptops¶

Le prime operazioni¶

  • Come prima cosa vengono fatte delle operazioni per migliorare la struttura del dataset e renderlo più consono per le successive analisi.
In [1]:
import numpy as np
np.set_printoptions(precision=2)
import plotly.express as px
import plotly.graph_objs as go
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt

laptops = pd.read_csv('data/project/laptop_price.csv', encoding = "latin")
laptops
Out[1]:
laptop_ID Company Product TypeName Inches ScreenResolution Cpu Ram Memory Gpu OpSys Weight Price_euros
0 1 Apple MacBook Pro Ultrabook 13.3 IPS Panel Retina Display 2560x1600 Intel Core i5 2.3GHz 8GB 128GB SSD Intel Iris Plus Graphics 640 macOS 1.37kg 1339.69
1 2 Apple Macbook Air Ultrabook 13.3 1440x900 Intel Core i5 1.8GHz 8GB 128GB Flash Storage Intel HD Graphics 6000 macOS 1.34kg 898.94
2 3 HP 250 G6 Notebook 15.6 Full HD 1920x1080 Intel Core i5 7200U 2.5GHz 8GB 256GB SSD Intel HD Graphics 620 No OS 1.86kg 575.00
3 4 Apple MacBook Pro Ultrabook 15.4 IPS Panel Retina Display 2880x1800 Intel Core i7 2.7GHz 16GB 512GB SSD AMD Radeon Pro 455 macOS 1.83kg 2537.45
4 5 Apple MacBook Pro Ultrabook 13.3 IPS Panel Retina Display 2560x1600 Intel Core i5 3.1GHz 8GB 256GB SSD Intel Iris Plus Graphics 650 macOS 1.37kg 1803.60
... ... ... ... ... ... ... ... ... ... ... ... ... ...
1298 1316 Lenovo Yoga 500-14ISK 2 in 1 Convertible 14.0 IPS Panel Full HD / Touchscreen 1920x1080 Intel Core i7 6500U 2.5GHz 4GB 128GB SSD Intel HD Graphics 520 Windows 10 1.8kg 638.00
1299 1317 Lenovo Yoga 900-13ISK 2 in 1 Convertible 13.3 IPS Panel Quad HD+ / Touchscreen 3200x1800 Intel Core i7 6500U 2.5GHz 16GB 512GB SSD Intel HD Graphics 520 Windows 10 1.3kg 1499.00
1300 1318 Lenovo IdeaPad 100S-14IBR Notebook 14.0 1366x768 Intel Celeron Dual Core N3050 1.6GHz 2GB 64GB Flash Storage Intel HD Graphics Windows 10 1.5kg 229.00
1301 1319 HP 15-AC110nv (i7-6500U/6GB/1TB/Radeon Notebook 15.6 1366x768 Intel Core i7 6500U 2.5GHz 6GB 1TB HDD AMD Radeon R5 M330 Windows 10 2.19kg 764.00
1302 1320 Asus X553SA-XX031T (N3050/4GB/500GB/W10) Notebook 15.6 1366x768 Intel Celeron Dual Core N3050 1.6GHz 4GB 500GB HDD Intel HD Graphics Windows 10 2.2kg 369.00

1303 rows × 13 columns

In [2]:
laptops['Main_Memory'] = laptops['Memory'].str.split("+").str[0]
laptops['Secondary_Memory'] = laptops['Memory'].str.split("+").str[1]
laptops['Main_Memory'] = laptops['Main_Memory'].str.strip()
laptops['Main_Memory_Type'] = laptops['Main_Memory'].str.split(" ").str[1:]
laptops['Main_Memory'] = laptops['Main_Memory'].str.split(" ").str[0]
laptops['Main_Memory_Type'] = laptops['Main_Memory_Type'].str.join(" ")
laptops['Operating_System'] = laptops['OpSys'].replace({'Windows 10' : 'Windows', 'Windows 10 S' : 'Windows', 'Windows 7' : 'Windows', 'Mac OS X' : 'Mac OS', 'macOS' : 'Mac OS' })
In [3]:
res=laptops['ScreenResolution'].str.split('x',n=1,expand=True)

#Creare colonna con nomi di tutte le CPU
laptops['Cpu_Name']=laptops['Cpu'].apply(lambda x:" ".join(x.split()[0:3]))

#Divide per categoria
def divisore(text):
    if text == 'Intel Core i7' or text == 'Intel Core i5' or text == 'Intel Core i3':
        return text
    else:
        if text.split()[0] == 'Intel':
            return 'Other Intel Processor'
        else:
            return 'AMD Processor'
                
laptops['Brand_CPU']=laptops['Cpu_Name'].apply(divisore)
laptops['TouchScreen']=laptops['ScreenResolution'].apply(lambda x:1 if 'Touchscreen' in x else 0)
laptops['IPS']=laptops['ScreenResolution'].apply(lambda x:1 if'IPS' in x else 0)
laptops['Brand_GPU'] = laptops['Gpu'].apply(lambda x:x.split()[0])

I grafici¶

  • Da qui in poi verranno mostrati i grafci con le varie analisi fatte sul dataset in questione.

Grafico a torta sui sistemi operativi più usati¶

In [4]:
fig = px.pie(laptops, values=laptops['Price_euros'], names=laptops['Operating_System'])
fig.show()

Istogrammi su categoria e produttori dei laptops¶

In [5]:
#Quantità laptops realizzati per produttore
fig = px.histogram(laptops['Company']).update_xaxes(categoryorder = 'total descending')
fig.update_layout(
    title ='Quantità laptops realizzati per produttore',
    xaxis_title = 'Produttori',
    yaxis_title = 'Quantità di pc',
    legend_title = 'Produttore'
)
fig.show()


#Quantità laptops per categoria
fig = px.histogram(laptops['TypeName'])
fig.update_xaxes(categoryorder = 'total descending')
fig.update_layout(
    title ='Quantità laptops per categoria',
    xaxis_title = 'Categoria',
    yaxis_title = 'Quantità di pc'
)
fig.show()


#Quantità laptops dei produttori per categoria
tmp = laptops.copy()
tmpMask = (tmp["Company"] != "Dell") & (tmp["Company"] != "Lenovo") & (tmp["Company"] != "HP") & (tmp["Company"] != "Asus") & (tmp["Company"] != "Acer")
tmp.loc[tmpMask, "Company"] = "Altro"
fig = px.histogram(tmp, x='TypeName', color='Company')
fig.update_xaxes(categoryorder = 'total descending')
fig.update_layout(
    title ='Quantità laptops dei produttori per categoria',
    xaxis_title = 'Categoria',
    yaxis_title = 'Quantità di pc',
    legend_traceorder="reversed",
    legend_title = 'Produttore'
)
fig.show()

Analisi sulla CPU¶

In [6]:
#Numero di computer per ogni CPU
fig = px.histogram(laptops['Brand_CPU'])
fig.update_xaxes(categoryorder = 'total descending')
fig.update_layout(
    title ='Quantità laptops per ogni modello CPU',
    xaxis_title = 'Modello CPU',
    yaxis_title = 'Quantità di pc'
)
fig.show()



#Distribuzione prezzi per tipo di CPU
fig = px.histogram(laptops, x=laptops['Brand_CPU'],y=laptops['Price_euros'], histfunc='avg')
fig.update_xaxes(categoryorder = 'array', categoryarray=['Intel Core i7', 'Intel Core i5', 'Other Intel Processor', 'Intel Core i3', 'AMD Processor'])
fig.update_layout(
    title ='Distribuzione prezzi dei laptops per modello di CPU',
    xaxis_title = 'Modello CPU',
    yaxis_title = 'Prezzo medio dei laptops [€]'
)
fig.show()


#Prezzi laptops per CPU montata
fig = go.Figure(data=go.Heatmap(
                   z=laptops['Price_euros'],
                   x=laptops['Brand_CPU'],
                   y=laptops['Operating_System'],
                   hoverongaps = False))
fig.update_layout(
    title ='Prezzi laptops per CPU montata',
    xaxis_title = 'Modello CPU',
    yaxis_title = 'Sistema Operativo'
)
fig.show()

Analisi sulla GPU¶

In [7]:
#Quantità laptops per ogni modello GPU
fig = px.histogram(laptops['Brand_GPU'])
fig.update_xaxes(categoryorder = 'total descending')
fig.update_layout(
    title ='Quantità laptops per ogni modello GPU',
    xaxis_title = 'Modello GPU',
    yaxis_title = 'Quantità di pc'
)
fig.show()


#Distribuzione prezzi dei laptops per modello di GPU
fig = px.histogram(laptops, x=laptops['Brand_GPU'],y=laptops['Price_euros'], histfunc='avg')
fig.update_xaxes(categoryorder = 'array', categoryarray=['Intel', 'Nvidia', 'AMD', 'ARM'])
fig.update_layout(
    title ='Distribuzione prezzi dei laptops per modello di GPU',
    xaxis_title = 'Modello GPU',
    yaxis_title = 'Prezzo medio dei laptops [€]'
)
fig.show()


#Prezzi laptops per GPU montata
fig = go.Figure(data=go.Heatmap(
                   z=laptops['Price_euros'],
                   x=laptops['Brand_GPU'],
                   y=laptops['Operating_System'],
                   hoverongaps = False))
fig.update_layout(
    title ='Prezzi laptops per GPU montata',
    xaxis_title = 'Modello GPU',
    yaxis_title = 'Sistema Operativo'
)
fig.show()

Distribuzione dei prezzi in base ai sistemi operativi¶

In [8]:
#Costo laptops per sistema operativo
fig = px.box(laptops, x=laptops['Price_euros'],y=laptops['Operating_System'], orientation="h")
fig.update_layout(
    title ='Costo laptops per sistema operativo',
    xaxis_title = 'Prezzo per unità',
    yaxis_title = 'Sistema Operativo'
)
fig.show()


#Distribuzione prezzi per sistema operativo
fig = px.histogram(laptops, x=laptops['Price_euros'], color='Operating_System')
fig.update_layout(
    title ='Distribuzione prezzi per sistema operativo',
    xaxis_title = 'Prezzo per unità',
    yaxis_title = 'Quantità di pc',
    legend_title = 'Sistema Operativo'
)
fig.show()


#Quantità laptops dei sistemi operativi per categoria (NO WINDOWS)
#È stato esscluso windows dalle analisi in quanto avrebbe falsato il risultato essendo il sistema operativo più comune in assoluto.
tmp = tmp.drop(tmp[tmp.Operating_System == "Windows"].index)
fig = px.histogram(tmp, x='TypeName', color='Operating_System')
fig.update_xaxes(categoryorder = 'total descending')
fig.update_layout(
    title ='Quantità laptops dei sistemi operativi per categoria (NO WINDOWS)',
    xaxis_title = 'Categoria',
    yaxis_title = 'Quantità di pc',
    legend_traceorder="reversed",
    legend_title = 'Sistema Operativo'
)
fig.show()
In [9]:
#Diffusione delle tipologie di memoria nelle varie fascie di prezzo
fig = plt.figure(figsize=(10,5))
ax = plt.axes()
fig.patch.set_facecolor("#FFFFFF")
ax.set_facecolor("#FFFFFF")
ax.set(xlabel='Prezzo per unità [€]', ylabel='Densità')
sns.kdeplot(data=laptops, x="Price_euros", hue="Main_Memory_Type",multiple="fill",palette="pastel");
plt.text(-800,1.3,"Diffusione delle tipologie di memoria nelle varie fascie di prezzo", {"font":"Arial", "weight":"bold", "size":12.5});
plt.legend(labels=["Ibrido", "HDD", "Flash", "SSD"], title = "Tipo di memoria")
Out[9]:
<matplotlib.legend.Legend at 0x2192d1c7a90>